package com.zc.study.designPattern.结构型设计模式.flyweightPattern;

/**
 *围棋游戏黑子,白子只有细微改变,大体相似
 * 故用享元模式来减少内存中实例对象的存在
 */
public class Test {
    public static void main(String[] args) {
        IgoChessman black1,black2,black3,white1,white2;
        IgochessmanFactory factory;

        //获取享元工厂对象
        factory = IgochessmanFactory.getInstance();

        //通过享元工厂获取3颗黑子
        black1 = factory.getIgochessman("b");
        black2 = factory.getIgochessman("b");
        black3 = factory.getIgochessman("b");
        System.out.println("判断两颗黑子是否相同:"+ (black1 == black2));

        //通过享元模式获取两颗白子
        white1 =factory.getIgochessman("w");
        white2 =factory.getIgochessman("w");
        System.out.println("判断两个白子是否相同:"+(white1 == white2));

        //显示棋子
        black1.display();
        black2.display();
        black3.display();
        white1.display();
        white2.display();
    }
}
